<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class AdminUserscore extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";
     //定义相对关联
     public function adminuser()
     {
         return $this->belongsTo(AdminUser::class, 'openid','openid')->visible(['nickname','headimgurl','sname','phone','address']);;
     }
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        //按openid查找
        if ($openid = input("openid")) {
            $where[] = ["openid", "like", "%" . $openid . "%"];
        }
        $list = self::with('adminuser')->order('score','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }
    public static function gettopList()
    {
        $where = [];
        $list = self::with('adminuser')->order('score','desc')->where($where)->limit(200)->select();
        return $list;
    }
      // 判断用户是否已经添加过了
      public static function findbyopenid($openid)
      {
          return self::where('openid',$openid)->find();
      }
}
